home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / smaltalk.lha / smalltalk-1.1.1 / BlockContext.st < prev    next >
Text File  |  1991-09-12  |  3KB  |  116 lines

  1. "======================================================================
  2. |
  3. |   BlockContext Method Definitions
  4. |
  5.  ======================================================================"
  6.  
  7.  
  8. "======================================================================
  9. |
  10. | Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  11. | Written by Steve Byrne.
  12. |
  13. | This file is part of GNU Smalltalk.
  14. |
  15. | GNU Smalltalk is free software; you can redistribute it and/or modify it
  16. | under the terms of the GNU General Public License as published by the Free
  17. | Software Foundation; either version 1, or (at your option) any later version.
  18. | GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
  19. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  20. | FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  21. | details.
  22. | You should have received a copy of the GNU General Public License along with
  23. | GNU Smalltalk; see the file COPYING.  If not, write to the Free Software
  24. | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  
  25. |
  26.  ======================================================================"
  27.  
  28.  
  29. "
  30. |     Change Log
  31. | ============================================================================
  32. | Author       Date       Change 
  33. | sbyrne     25 Apr 89      created.
  34. |
  35. "
  36.  
  37. Object variableSubclass: #BlockContext
  38.        instanceVariableNames: 'caller ip sp numArgs initialIP selector home'
  39.        classVariableNames: ''
  40.        poolDictionaries: ''
  41.        category: nil.
  42.  
  43. BlockContext comment: 
  44. 'My instances represent Smalltalk blocks, which are portions of executeable
  45. code that have access to the environment that they were declared in, take
  46. parameters, and can be passed around as objects to be executed by methods
  47. outside the current class.  Block contexts are sent a message to compute
  48. their value; this property can be used in the construction of control
  49. flow methods.  I also provide some methods that are used in the creation
  50. of Processes from blocks.' !
  51.  
  52.  
  53. !BlockContext methodsFor: 'basic'!
  54.  
  55. whileTrue: aBlock
  56.     [ self value ] whileTrue: [ aBlock value ].
  57.     ^nil
  58. !
  59.  
  60. whileFalse: aBlock
  61.     [ self value ] whileFalse: [ aBlock value ].
  62.     ^nil
  63. !
  64.  
  65. whileTrue
  66.     ^[ self value ] whileTrue: []
  67. !
  68.  
  69. whileFalse
  70.     ^[ self value ] whileFalse: []
  71. !!
  72.  
  73.  
  74.  
  75. !BlockContext methodsFor: 'multiple process'!
  76.  
  77. fork
  78.     self newProcess resume
  79. !
  80.  
  81. newProcess
  82.     | block |
  83.     block _ [ self value.
  84.               Processor terminateActive ].
  85.     block initBlock.          
  86.     ^Process on: block at: Processor activePriority
  87. !
  88.  
  89. newProcessWith: anArray
  90.     | block |
  91.     block _ [ self valueWithArguments: anArray.
  92.               Processor terminateActive ].
  93.     block initBlock.          
  94.     ^Process on: block at: Processor activePriority
  95. !!
  96.  
  97.  
  98.  
  99. !BlockContext methodsFor: 'scheduling'!
  100.  
  101. forkAt: priority
  102.     (self newProcess priority: priority) resume
  103. !!
  104.  
  105.  
  106.  
  107. !BlockContext methodsFor: 'private'!
  108.  
  109. initBlock 
  110.     ip _ initialIP.
  111.     sp _ 0.
  112.     caller _ nil
  113. !!
  114.